import 'package:flutter/material.dart';

///
/// 横向图文按钮
/// reverse：false=左图右文，true=左文右图
///
class QIconTitleHorizontalButton extends StatelessWidget {
  final bool reverse;
  final String icon;
  final String title;
  final double height;
  final double width;
  final double? fontSize;
  final GestureTapCallback? tapCallback;

  const QIconTitleHorizontalButton({
    Key? key,
    required this.title,
    required this.height,
    required this.width,
    required this.icon,
    this.fontSize,
    this.reverse = false,
    this.tapCallback,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (tapCallback != null) {
          tapCallback!();
        }
      },
      child: SizedBox(
        height: height,
        width: width,
        child: reverse
            ? Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Image.asset(icon, height: 20, width: 20),
                  const SizedBox(width: 2),
                  Text(
                    title,
                    style: TextStyle(fontSize: fontSize ?? 14, color: Colors.black),
                    textAlign: TextAlign.center,
                  )
                ],
              )
            : Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    title,
                    style: TextStyle(fontSize: fontSize ?? 14, color: Colors.black),
                    textAlign: TextAlign.center,
                  ),
                  const SizedBox(width: 2),
                  Image.asset(icon, height: 20, width: 20)
                ],
              ),
      ),
    );
  }
}
